
// 转换date对象的日期格式
export function dateFormat(obj, fmt) {
  let result = null
  if (typeof obj === 'string' && obj.length > 4) {
    obj = new Date(obj)
  }
  if (typeof obj === 'object' && obj !== null) {
    const demo = {
      'y+': obj.getFullYear(),
      'm+': obj.getMonth() + 1,
      'd+': obj.getDate(),
      'H+': obj.getHours(),
      'M+': obj.getMinutes(),
      's+': obj.getSeconds()
    }
    for (const k in demo) {
      const pattern = new RegExp('(' + k + ')')
      if (pattern.test(fmt)) {
        if (demo[k] < 10) {
          demo[k] = '0' + demo[k]
        }
        fmt = fmt.replace(RegExp.$1, demo[k])
      }
    }
    result = fmt
  } else {
    result = obj
  }
  return result
}
// 日期字符串转为date对象; 只支持 ‘yyyy-mm-dd HH:MM:ss’
export function stringToDate(val = String) {
  const list = val.split(' ')
  let result = null
  const reg = list[0].indexOf('-') === -1 ? '/' : '-'
  const temp = list[0].split(reg)
  temp[1] = Number(temp[1]) - 1
  const hours = list[1] ? list[1] : '00:00:00'
  result = new Date(...temp, ...hours.split(':'))
  return result
}
/*
 * 将时间戳或者中国标准时间处理成 2018-05-01 00:00:00  这种格式
 * @param {时间戳或者中国标准时间} timestamp
 * @param {一状态 } state   ture要时分秒  false不要时分秒
 */
export function timestampToTime(timestamp, state) {
  const date = new Date(timestamp) // 时间戳为10位需*1000，时间戳为13位的话不需乘1000
  const Y = date.getFullYear() + '-' // 年
  const M = (date.getMonth() + 1).toString().padStart(2, '0') + '-'
  const D =
    date
      .getDate()
      .toString()
      .padStart(2, '0') + ' '
  const h =
    date
      .getHours()
      .toString()
      .padStart(2, '0') + ':'
  const m =
    date
      .getMinutes()
      .toString()
      .padStart(2, '0') + ':'
  const s = date
    .getSeconds()
    .toString()
    .padStart(2, '0')
  return state ? Y + M + D + h + m + s : Y + M + D
}

// 将 年月日 时分 转化为 标准日期 格式以便回显 - yangxiaoying
export function handleDateRef(dateStr, gs = '/') {
  if (dateStr) {
    // const dateArr = dateStr.split(/[^\d]/) // ^ 匹配数字以外的字符 其实就是以\来匹配分割成数组
    const dateArr = dateStr.split(gs)
    dateArr.filter(Boolean)
    dateArr[1] = Number(dateArr[1]) - 1 // 标准月份减一
    return new Date(...dateArr)
  } else {
    return dateStr
  }
}
// 防抖
export function debounce(func, wait = 1000, immediate = false) {
  let timer, context, args
  // 延迟执行函数
  const later = () =>
    setTimeout(() => {
      timer = null // 延迟执行函数延迟执行后，重置定时器
      func.apply(context, args)
      context = args = null
    }, wait)
  // 每次实际调用的函数
  return function(...params) {
    if (!timer) {
      timer = later()
      if (immediate) {
        args = params
        func.apply(context, args)
      } else {
        context = this
        args = params
      }
    } else {
      clearTimeout(timer)
      timer = later()
    }
  }
}
// 防抖2
export const debounce2 = (func, wait = 1000) => {
  let timer

  // 每次实际调用的函数
  return function() {
    const args = arguments
    const th = this
    if (timer) clearTimeout(timer)
    var flag = !timer
    timer = setTimeout(() => {
      timer = null
    }, wait)
    if (flag) func.apply(th, args)
  }
}

/**
 * 函数节流
 * @param fn
 * @param interval
 * @returns {Function}
 * @constructor
 */
export const Throttle = (fn, t) => {
  let last
  let timer
  const interval = t || 500
  return function() {
    const args = arguments
    const now = +new Date()
    if (last && now - last < interval) {
      clearTimeout(timer)
      timer = setTimeout(() => {
        last = now
        fn.apply(this, args)
      }, interval)
    } else {
      last = now
      fn.apply(this, args)
    }
  }
}
// 获取当前日期 toSeconds:精确到秒
export function getNowFormatDate(toSeconds) {
  var date = new Date()
  var seperator1 = '-'
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var strDate = date.getDate()
  if (month >= 1 && month <= 9) {
    month = '0' + month
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = '0' + strDate
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate
  if (toSeconds) {
    currentdate += ` ${date.getHours()}:${date.getMinutes()}:${date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    }`
  }
  return currentdate
}
// 钱转大写
export function toSuperMoney(n) {
  if (n + '' === '0') return '零'
  const re = new RegExp('/^(0|[1-9]d*)(.d+)?$/')
  if (!re.test(n)) return ''
  var unit = '京亿万仟佰拾兆万仟佰拾亿仟佰拾万仟佰拾元角分'
  var str = ''
  n += '00'
  var p = n.indexOf('.')
  if (p >= 0) n = n.substring(0, p) + n.substr(p + 1, 2)
  unit = unit.substr(unit.length - n.length)
  for (var i = 0; i < n.length; i++) {
    str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i)
  }
  return str
    .replace(/零(仟|佰|拾|角)/g, '零')
    .replace(/(零)+/g, '零')
    .replace(/零(兆|万|亿|元)/g, '$1')
    .replace(/(兆|亿)万/g, '$1')
    .replace(/(京|兆)亿/g, '$1')
    .replace(/(京)兆/g, '$1')
    .replace(/(京|兆|亿|仟|佰|拾)(万?)(.)仟/g, '$1$2零$3仟')
    .replace(/^元零?|零分/g, '')
    .replace(/(元|角)$/g, '$1')
}
// 金钱大写转数字
export function toCommonMoney(n) {
  if (typeof n !== 'string' || n.length === 0) return
  const example = [
    ['零', 0],
    ['壹', 1],
    ['贰', 2],
    ['叁', 3],
    ['肆', 4],
    ['伍', 5],
    ['陆', 6],
    ['柒', 7],
    ['捌', 8],
    ['玖', 9]
  ]
  const numMap = new Map(example)
  const handleNum = function(str) {
    const first = str.indexOf('仟') < 0 ? 0 : numMap.get(str.charAt(str.indexOf('仟') - 1)) * 1000
    const second = str.indexOf('佰') < 0 ? 0 : numMap.get(str.charAt(str.indexOf('佰') - 1)) * 100
    const third = str.indexOf('拾') < 0 ? 0 : numMap.get(str.charAt(str.indexOf('拾') - 1)) * 10
    const fourth =
      str.indexOf('元') < 0
        ? 0
        : numMap.get(str.charAt(str.indexOf('元') - 1))
          ? numMap.get(str.charAt(str.indexOf('元') - 1))
          : 0
    const fifth = str.indexOf('角') < 0 ? 0 : numMap.get(str.charAt(str.indexOf('角') - 1)) * 0.1
    const sixth = str.indexOf('分') < 0 ? 0 : numMap.get(str.charAt(str.indexOf('分') - 1)) * 0.01
    return first + second + third + fourth + fifth + sixth
  }
  const arr = n.split('万').reverse()
  let num = 0
  arr.forEach((item, index) => {
    if (item.indexOf('罚款人民币') !== -1) {
      item = item.slice(item.indexOf('罚款人民币') + 5)
      if (item.length === 1) {
        num += numMap.get(item) * Math.pow(10000, index)
      } else {
        num += numMap.get(item.slice(-1)) * Math.pow(10000, index)
        num += handleNum(item) * Math.pow(10000, index)
      }
    } else {
      num += handleNum(item) * Math.pow(10000, index)
    }
  })
  return num.toString()
}

// 日期转大写 - yangxiaoying
export function toSuperDate(date, fmt) {
  let unitMapper = null
  let dateStr = ''
  let unit = []
  let month = ''
  let day = ''
  unit = [
    ['0', '〇'],
    ['1', '一'],
    ['2', '二'],
    ['3', '三'],
    ['4', '四'],
    ['5', '五'],
    ['6', '六'],
    ['7', '七'],
    ['8', '八'],
    ['9', '九'],
    ['a', '十']
  ]
  unitMapper = new Map(unit)
  month = date.getMonth() + 1
  day = date.getDate()
  dateStr = dateFormat(date, fmt)
  //  let re= new RegExp('(?<=\u5E74)1') 兼容火狐
  // dateStr = dateStr.replace(/(?<=\u5E74)1/, 'a')火狐不支持这种写法
  if (dateStr) {
    // 加 ‘十’ 字
    if (month > 10) {
      const re = new RegExp('(?<=\u5E74)1')
      dateStr = dateStr.replace(re, 'a')
    } else if (month === 10) {
      const re = new RegExp('(?<=\u5E74)10')
      dateStr = dateStr.replace(re, 'a')
    } else {
      const re = new RegExp('(?<=\u5E74)0')
      dateStr = dateStr.replace(re, '')
    }
    if (day < 10) {
      const re = new RegExp('(?<=\u6708)0')
      dateStr = dateStr.replace(re, '')
    } else if (day === 10) {
      const re = new RegExp('(?<=\u6708)10')
      dateStr = dateStr.replace(re, 'a')
    } else if (day === 20) {
      const re = new RegExp('(?<=\u6708)20')
      dateStr = dateStr.replace(re, '2a')
    } else if (day === 30) {
      const re = new RegExp('(?<=\u6708)30')
      dateStr = dateStr.replace(re, '3a')
    } else {
      const dayStr = 'a' + dateStr.slice(-2)
      dateStr = dateStr.slice(0, -2) + dayStr
    }
    for (const i of dateStr) {
      if ([...unitMapper.keys()].indexOf(i) >= 0) {
        dateStr = dateStr.replace(i, unitMapper.get(i))
      }
    }
  }
  return dateStr
}
// 根据身份证号计算年龄
export function GetAge(identityCard) {
  var len = (identityCard + '').length
  if (len === 0) {
    return ''
  } else {
    if (len !== 15 && len !== 18) {
      // 身份证号码只能为15位或18位其它不合法
      return ''
    }
  }
  var strBirthday = ''
  if (len === 18) {
    // 处理18位的身份证号码从号码中得到生日和码性别代
    strBirthday = identityCard.substr(6, 4) + '/' + identityCard.substr(10, 2) + '/' + identityCard.substr(12, 2)
  }
  if (len === 15) {
    strBirthday = '19' + identityCard.substr(6, 2) + '/' + identityCard.substr(8, 2) + '/' + identityCard.substr(10, 2)
  }
  // 时间字符串里，必须是“/”
  var birthDate = new Date(strBirthday)
  var nowDateTime = new Date()
  var age = nowDateTime.getFullYear() - birthDate.getFullYear()
  // 再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
  if (
    nowDateTime.getMonth() < birthDate.getMonth() ||
    (nowDateTime.getMonth() === birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())
  ) {
    age--
  }
  return age
}
// 根据身份证判断性别 true 男
export function GetSex(identityCard) {
  return parseInt(identityCard.substr(16, 1)) % 2 === 1
}
// 获取数组重复的元素
export function refrain(arr) {
  const tmp = []
  if (Array.isArray(arr)) {
    arr
      .concat()
      .sort()
      .sort((a, b) => {
        if (a === b && tmp.indexOf(a) === -1) tmp.push(a)
      })
  }
  return tmp
}
// 获取数组重复的元素 根据某种属性value去重
export function refrainWithPro(arr) {
  const res = new Map()
  return arr.filter(a => !res.has(a.value) && res.set(a.value, 1))
}
// 获取数组重复的元素 根据某种属性id去重
export function refrainWithProId(arr) {
  const res = new Map()
  return arr.filter(a => !res.has(a.id) && res.set(a.id, 1))
}
export function resetData(vm, attr) {
  // 还原目标属性初始值
  if (callType(attr) === 'String') {
    vm[attr] = vm.$options.data()[attr]
  }
  if (callType(attr) === 'Array') {
    attr.forEach(el => {
      vm[el] = vm.$options.data()[el]
    })
  }
}
export function resetVmData(vm) {
  // 还原所有值
  // vm.$data获取目前的data属性,然后利用同名覆盖的原理重置vm.$options.data()获得初始状态的值
  Object.assign(vm.$data, vm.$options.data())
}
// 数字转中文
export function sectionToChinese(section) {
  const chnNumChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
  const chnUnitChar = ['', '十', '百', '千']
  let strIns = ''
  let chnStr = ''
  let unitPos = 0
  let zero = true
  while (section > 0) {
    const v = section % 10
    if (v === 0) {
      if (!zero) {
        zero = true
        chnStr = chnNumChar[v] + chnStr
      }
    } else {
      zero = false
      strIns = chnNumChar[v]
      strIns += chnUnitChar[unitPos]
      chnStr = strIns + chnStr
    }
    unitPos++
    section = Math.floor(section / 10)
  }
  return chnStr
}
// 数字转中文简写
export function numToChinese(num) {
  if (!new RegExp('/^d*(.d*)?$/').test(num)) {
    alert('Number is wrong!')
    return 'Number is wrong!'
  }
  // eslint-disable-next-line no-array-constructor
  var AA = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九')
  // eslint-disable-next-line no-array-constructor
  var BB = new Array('', '十', '百', '千', '万', '亿', '点', '')
  var a = ('' + num).replace(/(^0*)/g, '').split('.')
  var k = 0
  var re = ''
  for (var i = a[0].length - 1; i >= 0; i--) {
    switch (k) {
      case 0:
        re = BB[7] + re
        break
      case 4:
        if (!new RegExp('0{4}\\d{' + (a[0].length - i - 1) + '}$').test(a[0])) re = BB[4] + re
        break
      case 8:
        re = BB[5] + re
        BB[7] = BB[5]
        k = 0
        break
    }
    if (k % 4 === 2 && a[0].charAt(i + 2) !== 0 && a[0].charAt(i + 1) === 0) re = AA[0] + re
    if (a[0].charAt(i) !== 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re
    k++
  }
  if (a.length > 1) {
    // 加上小数部分(如果有小数部分)
    re += BB[6]
    for (let i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)]
  }
  if (re === '一十') {
    re = '十'
  } else if (re.indexOf('一十') !== -1 && re.length === 3) {
    re = re.substring(1, re.length)
  }
  return re
}
/*
判断数据类型
* @param {任意}
* 输出数据格式为：Date,String,Math,Undefined,Null....
*/
export function callType(value) {
  const type = Object.prototype.toString
  const typeStr = type.call(value)
  return typeStr.slice(8, -1)
}
// 取文件后缀名
export function getFileType(filePath) {
  var startIndex = filePath.lastIndexOf('.')
  if (startIndex !== -1) return filePath.substring(startIndex + 1, filePath.length).toLowerCase()
  else return ''
}
/*
罗马数字转整数
* @param {String}
* 输出数据格式为：Number
*/
export function romanToInt(s) {
  const obj = {
    I: 1,
    V: 5,
    X: 10,
    L: 50,
    C: 100,
    D: 500,
    M: 1000
  }
  let num = 0
  for (let i = 0; i < s.length; i++) {
    if (obj[s[i]] < obj[s[i + 1]]) {
      num += obj[s[i + 1]] - obj[s[i]]
      i++
    } else {
      num += obj[s[i]]
    }
  }
  return num
}

/*
  整数转罗马数字
  * @param {Number}
  * 输出数据格式为：String
  */
export function intToRoman(num) {
  const M = ['', 'M', 'MM', 'MMM']
  const C = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']
  const X = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']
  const I = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
  return M[parseInt(num / 1000)] + C[parseInt((num % 1000) / 100)] + X[parseInt((num % 100) / 10)] + I[num % 10]
}

// base64转为Blob
export function dataURLtoBlob(dataurl) {
  var arr = dataurl.split(',')
  var mime = arr[0].match(/:(.*?);/)[1]
  var bstr = atob(arr[1])
  var n = bstr.length
  var u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new Blob([u8arr], {
    type: mime
  })
}

// base64转换为file
export function dataURLtoFile(dataurl, filename) {
  // 将base64转换为文件
  var arr = dataurl.split(',')
  var mime = arr[0].match(/:(.*?);/)[1]
  var bstr = atob(arr[1])
  var n = bstr.length
  var u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new File([u8arr], filename, {
    type: mime
  })
}
// Blob转为base64
export function blobToDataURL(blob, callback) {
  const a = new FileReader()
  a.onload = function(e) {
    callback(e.target.result)
  }
  a.readAsDataURL(blob)
}
// 处理图片旋转 方法
export function handleImgRotate(target) {
  const imgObj = document.createElement('img')
  imgObj.src = target[0].src
  const _h = imgObj.height
  const _w = imgObj.width

  const canvas = document.createElement('canvas')
  const ctx = canvas.getContext('2d')

  canvas.width = _h
  canvas.height = _w

  ctx.fillStyle = '#fff'
  ctx.fillRect(0, 0, _w, _h)
  ctx.rotate((90 * Math.PI) / 180)
  ctx.translate(0, -_h)
  ctx.drawImage(imgObj, 0, 0, _w, _h)

  return {
    path: canvas.toDataURL('image/jpeg'),
    file: dataURLtoFile(canvas.toDataURL('image/jpeg'))
  }
}
// 处理树形数据
export function getTreeData(data, child = 'children') {
  for (var i = 0; i < data.length; i++) {
    if (data[i][child]) {
      if (data[i][child].length < 1) {
        // children若为空数组，则将children设为undefined
        data[i][child] = undefined
      } else {
        // children若不为空数组，则继续 递归调用 本方法
        getTreeData(data[i][child], child)
      }
    }
  }
  return data
}
// 获取树形数据Name
export function getTreeName(data, id, child = 'children') {
  let name = ''
  for (var i = 0; i < data.length; i++) {
    if (data[i].id === id) {
      name = data[i].name
    } else if (data[i][child] && data[i][child].length > 0) {
      name = getTreeName(data[i][child], id, child)
    }
    if (name) break
  }
  return name
}
export function move(ele, stylename, target) {
  // 如果有透明度,就放大100倍
  if (stylename === 'opacity') target * 100
  // 如果有延迟器就清除
  if (ele.timer) clearInterval(ele.timer)
  ele.timer = setInterval(function() {
    // 先获取起点
    var start
    if (stylename === 'opacity') {
      // 获取到的是字符串,先转化为数字
      start = parseInt(getStyle(ele, stylename) * 100)
    } else if (stylename === 'zIndex') {
      ele.style.zIndex = target
      clearInterval(ele.timer)
      return
    } else {
      start = parseInt(getStyle(ele, stylename))
    }
    // 设置每一步走多少,终点-起点/步数,越靠近终点移动越慢
    var step = (target - start) / 10
    // 设置边缘值
    if (Math.abs(step) < 1) {
      step = step > 0 ? 1 : Math.floor(step)
    }
    // 开始运动,起点+步进距离,因为是透明所以最终值除100
    if (stylename === 'opacity') {
      ele.style.opacity = (start + step) / 100
    } else {
      ele.style[stylename] = start + step + 'px'
    }
    // 终点,优化了临界值
    if (start + step === target || Math.abs(target - start) < step) {
      if (stylename === 'opacity') {
        ele.style[stylename] = target
      } else {
        ele.style[stylename] = target + 'px'
      }

      clearInterval(ele.timer)
      console.log('stop ...')
    }
  }, 17)
}
// 获取元素的样式目前值
function getStyle(ele, stylename) {
  // 兼容写法,IE没有getComputedStyle,2个参数,一个元素,另一个不用写
  if (getComputedStyle) {
    return getComputedStyle(ele)[stylename]
  } else {
    // IE写法,
    return ele.currentStyle[stylename]
  }
}
// 下载
export function downloadBlob(url, name) {
  const link = document.createElement('a')
  link.href = url
  link.setAttribute('download', name)
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}

// 错误处理方式
export function erroBack(fnc, vm) {
  if (!fnc) return
  vm.$confirm('数据请求失败,请选择返回上一级或者重新发送请求', '提示', {
    confirmButtonText: '返回上一级',
    cancelButtonText: '重新请求',
    type: 'warning ',
    showClose: false
  })
    .then(() => {
      vm.$router.go(-1)
    })
    .catch(() => {
      fnc()
    })
}
export function adminDebounce(func, wait, immediate) {
  let timeout, args, context, timestamp, result

  const later = function() {
    // 据上一次触发时间间隔
    const last = +new Date() - timestamp

    // 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
    if (last < wait && last > 0) {
      timeout = setTimeout(later, wait - last)
    } else {
      timeout = null
      // 如果设定为immediate===true，因为开始边界已经调用过了此处无需调用
      if (!immediate) {
        result = func.apply(context, args)
        if (!timeout) context = args = null
      }
    }
  }

  return function(...args) {
    context = this
    timestamp = +new Date()
    const callNow = immediate && !timeout
    // 如果延时不存在，重新设定延时
    if (!timeout) timeout = setTimeout(later, wait)
    if (callNow) {
      result = func.apply(context, args)
      context = args = null
    }

    return result
  }
}
export function deepClone(o) {
  // 判断如果不是引用类型，直接返回数据即可
  if (typeof o === 'string' || typeof o === 'number' || typeof o === 'boolean' || typeof o === 'undefined') {
    return o
  } else if (Array.isArray(o)) { // 如果是数组，则定义一个新数组，完成复制后返回
    // 注意，这里判断数组不能用typeof，因为typeof Array 返回的是object
    console.log(typeof []) // --> object
    var _arr = []
    o.forEach(item => { _arr.push(item) })
    return _arr
  } else if (typeof o === 'object') {
    var _o = {}
    for (const key in o) {
      _o[key] = deepClone(o[key])
    }
    return _o
  }
}

// 处理树形数据
export function getTreeInfo(data, child = 'child') {
  const newArr = []
  for (var i = 0; i < data.length; i++) {
    newArr.push({ 'text': data[i].name, 'children': data[i].child })
  }
  for (let index = 0; index < newArr.length; index++) {
    if (newArr[index].children) {
      for (let j = 0; j < newArr[index].children.length; j++) {
        // console.log(newArr[index].children[j])
        newArr[index].children[j].text = newArr[index].children[j].name
        newArr[index].children[j].children = newArr[index].children[j].child
      }
    }
  }
  return newArr
}
export function comProgress(num = 0, checkNum) {
  if (!num) return 0
  if (!checkNum) return 0
  if (checkNum > num) return 0

  return Math.floor((checkNum / num) * 100) || 0
}
export function comAnswerType(num) {
  if (!num && num !== 0) {
    return '混合题'
  }
  switch (Number(num)) {
    case 0:
      return '单选题'
    case 1:
      return '多选题'
    case 2:
      return '判断题'
    case 3:
      return '填空题'
    case 4:
      return '图片题'
    case 5:
      return '视频题'
    case 6:
      return '简答题'
    case 7:
      return '论述题'
    case 8:
      return '实操题'
    default:
      return '混合题'
  }
}
/**
 * [通过参数名获取url中的参数值]
 * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
 * @param  {[string]} queryName [参数名]
 * @return {[string]}           [参数值]
 */
// hash	从井号 (#) 开始的 URL（锚）
// host	主机名和当前 URL 的端口号
// hostname	当前 URL 的主机名
// href	完整的 URL
// pathname	当前 URL 的路径部分
// port	当前 URL 的端口号
// protocol	当前 URL 的协议
// search	从问号 (?) 开始的 URL（查询部分
export function getQueryValue(queryName) {
  // decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。
  var query = decodeURI(window.location.search.substring(1))
  var vars = query.split('&')
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split('=')
    if (pair[0] === queryName) { return pair[1] }
  }
  return null
}
// 秒转分钟
export function formatSeconds(value = 0) {
  let result = parseInt(value)
  const m = Math.floor(result / 60)
  result = `${m}分钟`
  return result
}
// 秒转事分秒
export function formatSecondsPluse(value = 0) {
  var theTime = parseInt(value)// 秒
  var theTime1 = 0// 分
  var theTime2 = 0// 小时
  if (theTime > 60) {
    theTime1 = parseInt(theTime / 60)
    theTime = parseInt(theTime % 60)
    if (theTime1 > 60) {
      theTime2 = parseInt(theTime1 / 60)
      theTime1 = parseInt(theTime1 % 60)
    }
  }
  var result = '' + parseInt(theTime) + '秒'
  if (theTime1 > 0) {
    result = '' + parseInt(theTime1) + '分' + result
  }
  if (theTime2 > 0) {
    result = '' + parseInt(theTime2) + '小时' + result
  }
  return result
}
export function debounceP(fn, delay = 300) {
  let timer = null
  let flag = true
  return function() {
    if (timer) {
      clearTimeout(timer)
      timer = null
    }
    if (flag === true) {
      fn.apply(this, arguments)
      flag = false
    }
    timer = setTimeout(() => {
      flag = true
      timer = null
    }, delay)
  }
}
export function isBase64(str) {
  if (str === '' || str.trim() === '' || callType((str * 1)) === 'Number' && !isNaN((str * 1))) {
    return false
  }
  try {
    return btoa(atob(str)) === str
  } catch (err) {
    return false
  }
}
// 数字转以下
export function NumTransform(a) {
  if (a <= 999) return a
  let str = ''
  const value = Math.floor(a / 1000)
  if (value < 10 && value > 0) {
    str = `${value}K`
  } else if (value >= 10 && value < 100000) {
    str = `${value / 10}W`
  } else {
    str = `${value / 100000}亿`
  }
  return str
}
